clear all
set more off

// This do file generates Columns (3)& (4) of Table 4 for Party Secretaries and Mayors

cd "_______"
log using "log_Sec_Mayor_Characteristics_indivcity.log"
use "PM10_locoff_befandaft_merge_collapse.dta"
encode name, gen(indiv)
global ctr_sec_demo="malehan femalehan malenonhan" 
global ctr_sec_poly="yearsinpos yearstore match_pr befenterprise befresearch befsecretary befctymayor befctysec befcitymayor befcitysec befcentralgov befyearsincity befyearsinpr  befotherprov"
global ctr_sec_edu="ft_col ft_stem ft_key colgnb col78 pt1 pt2"
local ctr_sec_demo $ctr_sec_demo
local ctr_sec_poly $ctr_sec_poly
local ctr_sec_edu $ctr_sec_edu
local ctr_characteristics : list ctr_sec_demo | ctr_sec_edu
local ctr_characteristics: list ctr_characteristics| ctr_sec_poly 
global ctr_characteristics `ctr_characteristics'

// CityxSecretary
preserve
collapse (mean) $ctr_characteristics, by(indiv id)
tabstat $ctr_characteristics, statistics(mean sd count) save
return list
matrix PSStats=r(StatTotal)'
putexcel set Stata16_SumStats_Sec_indivcity, replace
putexcel A2=matrix(PSStats),rownames

restore
encode mayor_name, gen(m_indiv) 

global ctr_mayor_demo="m_malehan m_femalehan m_malenonhan" 
global ctr_mayor_poly="m_yearsinpos m_yearstore m_match_pr m_befenterprise m_befresearch m_befsecretary m_befctymayor m_befctysec m_befcitymayor m_befcitysec m_befcentralgov m_befyearsincity m_befyearsinpr m_befotherprov"
global ctr_mayor_edu="m_ft_col m_ft_stem m_ft_key m_colgnb m_col78 m_pt1 m_pt2"
local ctr_mayor_demo $ctr_mayor_demo
local ctr_mayor_poly $ctr_mayor_poly
local ctr_mayor_edu $ctr_mayor_edu
local ctr_m_characteristics : list ctr_mayor_demo | ctr_mayor_edu
local ctr_m_characteristics: list ctr_m_characteristics| ctr_mayor_poly 
global ctr_m_characteristics `ctr_m_characteristics'

// CityxMayor
preserve
collapse (mean) $ctr_m_characteristics, by(m_indiv id)
tabstat $ctr_m_characteristics, statistics(mean sd count) save
return list
matrix MStats=r(StatTotal)'
putexcel set Stata16_SumStats_Mayor_indivcity, replace
putexcel A2=matrix(MStats),rownames

restore
log close
